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

2023年12月1日 星期五

javascript, python

package的入口>>

js:

index.js

py:

__init__.py
-------------------------------------------
import 的差異>>

js:

impot {...} from '...'

import XX as XX from '...'

py:

import package as nickName

import dir.package

from package import component

-------------------------------------------

 檔案當前路徑>>

py:

os.getcwd() 

php:

$_SERVER['PHP_SELF'], __FILE__

-------------------------------------------

專案當前路徑>>

-------------------------------------------

數值類型>>

js:

typeof(...)

py:

type(...)

php:

gettype()

-------------------------------------------

undefined, null>>

js:

... == null

typeof(...) == 'undefined'

py:

... is None

php:

isset(...), empty(...), is_null(...)

-------------------------------------------

2023年11月4日 星期六

game

http://www.k73.com/down/psp/3854.html http://www.k73.com/down/psp/2049.html http://www.k73.com/down/psp/1810.html http://www.k73.com/down/psp/1726.html http://www.k73.com/down/psp/1700.html http://www.k73.com/down/psp/971.html http://www.k73.com/down/psp/975.html http://www.k73.com/down/psp/866.html http://www.k73.com/down/psp/821.html http://www.k73.com/down/psp/755.html http://www.k73.com/down/psp/754.html http://www.k73.com/down/psp/717.html http://www.k73.com/down/psp/467.html http://www.k73.com/down/psp/4148.html http://www.k73.com/down/psp/4257.html http://www.k73.com/down/psp/4252.html http://www.k73.com/down/psp/4373.html http://www.k73.com/down/psp/4370.html http://www.k73.com/down/psp/4405.html http://www.k73.com/down/psp/4399.html http://www.k73.com/down/psp/4442.html http://www.k73.com/down/psp/4451.html http://www.k73.com/down/psp/4703.html -http://www.k73.com/down/psp/4632.html -http://www.k73.com/down/psp/4483.html http://www.k73.com/down/psp/7097.html http://www.k73.com/down/psp/6919.html http://www.k73.com/down/psp/7078.html http://www.k73.com/down/psp/7304.html http://www.k73.com/down/psp/7327.html http://www.k73.com/down/psp/7089.html http://www.k73.com/down/psp/7077.html http://www.k73.com/down/psp/7357.html http://www.k73.com/down/psp/8385.html http://www.k73.com/down/psp/8150.html -http://www.k73.com/down/psp/8519.html -http://www.k73.com/down/psp/9191.html http://www.k73.com/down/psp/11817.html http://www.k73.com/down/psp/11872.html http://www.k73.com/down/psp/12524.html http://www.k73.com/down/psp/13217.html http://www.k73.com/down/psp/13038.html http://www.k73.com/down/psp/13459.html http://www.k73.com/down/psp/15474.html http://www.k73.com/down/psp/14921.html -http://www.k73.com/down/psp/17799.html -http://www.k73.com/down/psp/19344.html http://www.k73.com/down/psp/25980.html http://www.k73.com/down/psp/29341.html http://www.k73.com/down/psp/37114.html http://www.k73.com/down/psp/29400.html http://www.k73.com/down/psp/47660.html --------------------------------------------- http://www.k73.com/down/psp/160153.html http://www.k73.com/down/psp/66468.html http://www.k73.com/down/psp/66580.html

2023年10月20日 星期五

2022年8月22日 星期一

php 命令模式(路徑問題)


// 校正命令模式的 dir
chdir(__DIR__);

function is_cli() {
  if (php_sapi_name() === 'cli') {
    return true;
  }
  if (defined("STDIN")) {
    return true;
  }
  if (!isset($_SERVER["REMOTE_ADDR"]) || empty($_SERVER["REMOTE_ADDR"])) {
    return true;
  }
  return false;
}

php include, require 路徑問題

 PHP中include和require絕對路徑、相對路徑問題
-Advertisement-
Play Games
在寫PHP程式時,經常要用到include或require包含其他文件,但是各文件里包含的文件多了之後,就會產生路徑問題。 如下目錄: <web>(網站根目錄) ├<A>文件夾 │ │ │ └1.php ├<B>文件夾 │ │ │ └2.php └index.php 現在根目錄下的index.php ...

在寫PHP程式時,經常要用到include或require包含其他文件,但是各文件里包含的文件多了之後,就會產生路徑問題。

如下目錄:

<web>(網站根目錄)  
 ├<A>文件夾  
 │ │  
 │ └1.php  
 ├<B>文件夾  
 │ │  
 │ └2.php  
 └index.php

現在根目錄下的index.php要包含A文件夾內的1.php文件,則用include "./A/1.php"即可

而1文件夾內的1.php又包含了B文件夾內的2.php,則1.php內寫上include "../B/2.PHP"即可

可是要知道,當index.php包含了1.php之後,編譯是在index.php里進行的

也就是index.php所包含文件里的include都是相對於index.php的

那麼1.php被包含進index.php里了,那麼就要相對於index.php尋找2.php了
而上面說了,1.php里寫的是include "../B/2.php",現在編譯文件已經相對於網站根目錄了(即相對於index.php)
"../"則意味著還要再返回上一級目錄尋找,那麼怎麼會找得到。

在網上也尋找過一些方法,最好的辦法還是都採用絕對路徑方法較妥。
可以定義一個單入口文件,將要包含的文件包含進來
定義一個常量define("__ROOT__",dirname(__FILE__));,那麼在寫後面的文件過程中,只需要採用絕對方式,加上__ROOT__就行了。

require dirname(__FILE__) . '/library/Zend/Loader.php';

2021年8月14日 星期六

(node.js impoet)__filename, __dirname

import { dirname } from 'path';
import { fileURLToPath } from 'url';

const  __filename = fileURLToPath(import.meta.url);

const  __dirname = dirname(__filename)