[英]How do I get my data to display based on URL data?
I'm trying to get some dynamic content to display based on UTMs in my URL. 我正在尝试根据我的URL中的UTM显示一些动态内容。 While I can call the function in the browser to get the content to display, it isn't doing so on page load. 虽然我可以在浏览器中调用该函数来显示内容,但在页面加载时却没有这样做。 (Function works, but my timing must be off) (功能有效,但我的时间必须关闭)
I've tried to change the order in which I call jQuery and my JS file, but either way it doesn't show unless I paste my function into chrome dev tools. 我试图改变我调用jQuery和我的JS文件的顺序,但除非我将我的函数粘贴到chrome dev工具中,否则它不会显示。
Here's the relevant part of the function: 这是函数的相关部分:
// regex to find the URL param above
var dynamicContent = getParameterByName('dc');
$(document).ready(function() {
if (dynamicContent == 'fintech') {
$('#fintech').show();
}
else if (dynamicContent == 'martech') {
$('#martech').show();
}
//... excluded remaining options
else {
$('#default-content').show();
}
And the HTML: 和HTML:
<span id="default-content" class="dynamic-content">Tech</span>
<span id="fintech" class="dynamic-content">Fintech</span>
<span id="martech" class="dynamic-content">Martech</span>
<!-- excluded remaining options -->
And here's my header in case there's a different way I should be calling everything: 这是我的标题,以防我应该调用一切的不同方式:
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
<noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="assets/dynamic.js" type="text/javascript"></script>
</head>
Again, as copying/pasting my code into dev tools after the page load works, how do I time it so that this function runs on page load? 同样,在页面加载工作后将我的代码复制/粘贴到开发工具中时,如何计算它以使该函数在页面加载时运行?
Thanks. 谢谢。
Maybe try this: 也许试试这个:
$(window).on('load', function () {
var dynamicContent = getParameterByName('dc');
if (dynamicContent == 'fintech') {
$('#fintech').show();
}
else if (dynamicContent == 'martech') {
$('#martech').show();
}
//... excluded remaining options
else {
$('#default-content').show();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.