如何获取使用http://sin1.g.adnxs.com
这是我的代码
<div id="testingurl">
<div class="ads98E6LYS20621080">
<!-- we are getting this script dynamically -->
<iframe src="http://testing.com">
if the anchor link start with http://sin1.g.adnxs.com then alert
</iframe>
<!-- we are getting this script dynamically -->
</div>
</div>
答案 0 :(得分:0)
使用此逻辑
$( document ).ready(function() {
if (window.location.href.startsWith('http://sin1.g.adnxs.com')){
alert('Your message') ;
}
});
答案 1 :(得分:0)
你看起来像这样:
if (window.location.href.indexOf("http://www.sin1.g.adnxs.com") > -1) {
alert(window.location.href);
}
答案 2 :(得分:0)
if(window.location.origin == 'http://sin1.g.adnxs.com'){
alert('some alert');
}
答案 3 :(得分:0)
正如其他建议的那样,您可以使用window.location.origin来获取该URL 例如:
if(window.location.origin === 'http://sin1.g.adnxs.com'){
alert('alert');
}
通常你可以使用window.location:
window.location.href returns the href (URL) of the current page
window.location.hostname returns the domain name of the web host
window.location.pathname returns the path and filename of current page
window.location.protocol returns the web protocol used (http:// or https://)
window.location.assign loads a new document
可在此处找到更多信息:
https://developer.mozilla.org/en-US/docs/Web/API/Window.location
修改强>
请查看以下示例。
如果您有两个网页,则为parent.html和content.html以及content.html
使用iframe
在.html中显示。
如果您想在content.html中查看parent.html的网址,可以使用以下脚本:
-------------------------- parent.html
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<style>
</style>
<script>
window.name = 'parent';
</script>
</head>
<body>
PARENT
<iframe src="content.html" width="200" height="200"></iframe>
</body>
</html>
-------------------------- content.html
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<style>
body {
background-color: red;
}
</style>
<script>
app = {
start: function () {
window.name = 'content';
var parent = window.parent;
console.log(parent.name);
if (parent.location.origin === 'http://sin1.g.adnxs.com') {
alert('alert');
}
}
};
</script>
</head>
<body onload="app.start();">
CONTENT
</body>
</html>