Daz*_*Cat 102 javascript url
是否可以从URL调用javascript函数?我基本上试图在我无法访问源的页面中利用JS方法.
就像是: http://www.example.com/mypage.aspx?javascript:printHelloWorld()
我知道如果你把javascript:alert("Hello World");它放到地址栏就行了.
我怀疑答案是否定的,只是想知道是否有办法做到这一点.
hfa*_*azm 22
写在地址栏中
javascript:alert("hi");
Run Code Online (Sandbox Code Playgroud)
确保你在开头写:javascript:
小智 16
您可以使用数据URI.例如:
data:text/html,<script>alert('hi');</script>
欲了解更多信息,请访问:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
关于window.location.hash属性:
返回 URL 的锚点部分。
//Assume that the current URL is
var URL = "http://www.example.com/test.htm#part2";
var x = window.location.hash;
//The result of x will be:
x = "#part2"
Run Code Online (Sandbox Code Playgroud)
示例2:
$(function(){
setTimeout(function(){
var id = document.location.hash;
$(id).click().blur();
}, 200);
})
Run Code Online (Sandbox Code Playgroud)
示例3:
var hash = "#search" || window.location.hash;
window.location.hash = hash;
switch(hash){
case "#search":
selectPanel("pnlSearch");
break;
case "#advsearch":
case "#admin":
}
Run Code Online (Sandbox Code Playgroud)
小智 6
/test.html#alert('heello")
test.html
<button onClick="eval(document.location.hash.substring(1))">do it</button>
Run Code Online (Sandbox Code Playgroud)
您还可以放置以下内容
<a href='javascript:alert("hello world!");'>Click me</a>
Run Code Online (Sandbox Code Playgroud)
到您的html代码,并且当您单击“单击我”超链接时,javascript将出现在网址栏中,并且“警告”对话框将显示
| 归档时间: |
|
| 查看次数: |
271356 次 |
| 最近记录: |