2024年10月12日 星期六

Javascript開新視窗Tips

 

張貼者: Caesar Chi
開發網站介面的時候,常常會遇到空間不足的問題。瀏覽器大小就這樣,要放進網頁的資訊卻那麼多,該怎麼辦呢?

如果只是單純顯示資料,用AJAX呼叫回傳,顯示在select tag或div裡面就可以了。這樣介面簡潔,操作也不複雜。可是,如果需要更多互動的話,用AJAX,開發人員辛苦之外,介面太複雜維護不易,用戶用起來也不見得舒服。

這時候,開個小視窗另外操作,必要時也可以回傳結果到母網頁,對開發人員和用戶來說,應該都可以是權宜的好辦法。

window.open很常用也很簡單,本篇分基本型、完整型、遙控型三方面介紹,接下來就直接進範例嚕:

1.基本型
window.open ('page.html');

這是給只是想丟資料出來的人用的,或是想要強制另外開視窗。不過,真是這樣的話,用Yahoo!會更好。當然有時也會,需要用程式來判斷網頁方向也說不定。簡而言之,這個是方便記憶用的。

2.完整型
window.open ('page.html', '_blank', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no');

應該大部分會用到的是這行吧!先給目標URL,其次是開啟的目標,等同a tag的target屬性。第三個參數,就是給被開啟的瀏覽器設定,設定參數在上面的範例應該都有了,如果有缺漏請跟我說喔^__^。

3.遙控型
var new_window=window.open( ... );
if( new_window.opener == null ){ new_window.opener=window; }

這裡展示的是開啟新視窗之後,還想要繼續對新開的視窗做操作時,我們就可以用一個變數接收window.open()的回傳,如此就可以追蹤新開的視窗。新視窗也可以透過window.opener,將特定的資訊回傳給母視窗。

例如:在新視窗裡用:
window.opener.document.getElementById('obj').innerHTML="XXX";
或者
window.opener.location = 'http://......';
就可以從新視窗控制母視窗的網頁,執行如訊息回傳,重導網址,或是其他功能。

但是,有些舊版的browser不會自動建立新視窗和母視窗之間的關連,也就是new_window.opener這個屬性。所以後面的這個 if 敘述,就能確保opener保持在正確的設定。新視窗和母視窗溝通時,才不會發生找不到媽媽(opener)的問題。

這個 if 很重要喔!雖然新版的瀏覽器多都有支援 opener ,但為了確保安全,還是請記得加上去。

以上,謝謝收看。

2024年9月14日 星期六

pyqt Qwidget 可呼叫

 DrawChildren
DrawWindowBackground
IgnoreMask
PaintDeviceMetric
PdmDepth
PdmDevicePixelRatio
PdmDevicePixelRatioScaled
PdmDpiX
PdmDpiY
PdmHeight
PdmHeightMM
PdmNumColors
PdmPhysicalDpiX
PdmPhysicalDpiY
PdmWidth
PdmWidthMM
RenderFlag
RenderFlags
__class__
__delattr__
__dict__
__dir__
__doc__
__eq__
__format__
__ge__
__getattr__
__getattribute__
__getstate__
__gt__
__hash__
__init__
__init_subclass__
__le__
__lt__
__module__
__ne__
__new__
__reduce__
__reduce_ex__
__repr__
__setattr__
__sizeof__
__str__
__subclasshook__
__weakref__
acceptDrops
accessibleDescription
accessibleName
actionEvent
actions
activateWindow
addAction
addActions
adjustSize
autoFillBackground
backgroundRole
baseSize
blockSignals
changeEvent
childAt
childEvent
children
childrenRect
childrenRegion
clearFocus
clearMask
close
closeEvent
colorCount
connectNotify
contentsMargins
contentsRect
contextMenuEvent
contextMenuPolicy
create
createWindowContainer
cursor
customContextMenuRequested
customEvent
deleteLater
depth
destroy
destroyed
devType
devicePixelRatio
devicePixelRatioF
devicePixelRatioFScale
disconnect
disconnectNotify
dragEnterEvent
dragLeaveEvent
dragMoveEvent
dropEvent
dumpObjectInfo
dumpObjectTree
dynamicPropertyNames
effectiveWinId
ensurePolished
enterEvent
event
eventFilter
find
findChild
findChildren
focusInEvent
focusNextChild
focusNextPrevChild
focusOutEvent
focusPolicy
focusPreviousChild
focusProxy
focusWidget
font
fontInfo
fontMetrics
foregroundRole
frameGeometry
frameSize
geometry
getContentsMargins
grab
grabGesture
grabKeyboard
grabMouse
grabShortcut
graphicsEffect
graphicsProxyWidget
hasFocus
hasHeightForWidth
hasMouseTracking
hasTabletTracking
height
heightForWidth
heightMM
hide
hideEvent
inherits
initPainter
inputMethodEvent
inputMethodHints
inputMethodQuery
insertAction
insertActions
installEventFilter
isActiveWindow
isAncestorOf
isEnabled
isEnabledTo
isFullScreen
isHidden
isLeftToRight
isMaximized
isMinimized
isModal
isRightToLeft
isSignalConnected
isVisible
isVisibleTo
isWidgetType
isWindow
isWindowModified
isWindowType
keyPressEvent
keyReleaseEvent
keyboardGrabber
killTimer
layout
layoutDirection
leaveEvent
locale
logicalDpiX
logicalDpiY
lower
mapFrom
mapFromGlobal
mapFromParent
mapTo
mapToGlobal
mapToParent
mask
maximumHeight
maximumSize
maximumWidth
metaObject
metric
minimumHeight
minimumSize
minimumSizeHint
minimumWidth
mouseDoubleClickEvent
mouseGrabber
mouseMoveEvent
mousePressEvent
mouseReleaseEvent
move
moveEvent
moveToThread
nativeEvent
nativeParentWidget
nextInFocusChain
normalGeometry
objectName
objectNameChanged
overrideWindowFlags
overrideWindowState
paintEngine
paintEvent
paintingActive
palette
parent
parentWidget
physicalDpiX
physicalDpiY
pos
previousInFocusChain
property
pyqtConfigure
raise_
receivers
rect
releaseKeyboard
releaseMouse
releaseShortcut
removeAction
removeEventFilter
render
repaint
resize
resizeEvent
restoreGeometry
saveGeometry
screen
scroll
sender
senderSignalIndex
setAcceptDrops
setAccessibleDescription
setAccessibleName
setAttribute
setAutoFillBackground
setBackgroundRole
setBaseSize
setContentsMargins
setContextMenuPolicy
setCursor
setDisabled
setEnabled
setFixedHeight
setFixedSize
setFixedWidth
setFocus
setFocusPolicy
setFocusProxy
setFont
setForegroundRole
setGeometry
setGraphicsEffect
setHidden
setInputMethodHints
setLayout
setLayoutDirection
setLocale
setMask
setMaximumHeight
setMaximumSize
setMaximumWidth
setMinimumHeight
setMinimumSize
setMinimumWidth
setMouseTracking
setObjectName
setPalette
setParent
setProperty
setShortcutAutoRepeat
setShortcutEnabled
setSizeIncrement
setSizePolicy
setStatusTip
setStyle
setStyleSheet
setTabOrder
setTabletTracking
setToolTip
setToolTipDuration
setUpdatesEnabled
setVisible
setWhatsThis
setWindowFilePath
setWindowFlag
setWindowFlags
setWindowIcon
setWindowIconText
setWindowModality
setWindowModified
setWindowOpacity
setWindowRole
setWindowState
setWindowTitle
sharedPainter
show
showEvent
showFullScreen
showMaximized
showMinimized
showNormal
signalsBlocked
size
sizeHint
sizeIncrement
sizePolicy
stackUnder
startTimer
staticMetaObject
statusTip
style
styleSheet
tabletEvent
testAttribute
thread
timerEvent
toolTip
toolTipDuration
tr
underMouse
ungrabGesture
unsetCursor
unsetLayoutDirection
unsetLocale
update
updateGeometry
updateMicroFocus
updatesEnabled
visibleRegion
whatsThis
wheelEvent
width
widthMM
winId
window
windowFilePath
windowFlags
windowHandle
windowIcon
windowIconChanged
windowIconText
windowIconTextChanged
windowModality
windowOpacity
windowRole
windowState
windowTitle
windowTitleChanged
windowType
x
y