如何在内容页面访问母版页javascript变量 [英] How to access master page javascript variable at content page
本文介绍了如何在内容页面访问母版页javascript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi...
I am using master page(Master3.master) in my application. I have applied javascript to find master page <div> width. I get div width successfully in javascript variable using following code at master head tag :
<script type="text/javascript">
function getwidth()
{
var content_div = document.getElementById('content');
var content_width = content_div.clientWidth;
alert('content_width=' + content_width + 'px');
}
</script>
but now i want to show this div width(content_width )at content page named "ContactUs_Design.aspx" that access above MasterPage.
My content page and master page are in different different folder and i am adding master page dynamically to content page.
I want to use variable 'content_width' at "ContactUs_Design.aspx" to show.
How can i find this....????
Thanks
Sunil Sharma
推荐答案
你好,
如果您正在使用JavaScript,并且想要访问主页的内容页面,然后只需将javascript代码放在母版页的head标签部分。通过这种方式,当您添加任何与该母版页链接的内容页面时,您将看到在该页面上工作的java脚本。
Hello,
If you are using JavaScript, and Want to access is on Content Page of Masterpage, then simply put the javascript code in the , head tag section of masterpage. By this , when you will, add any content page, linked with that master page, you will see java script working on that contantpage.
这是我在母版页上包含div的方式(外部ContentPlaceHolder):
This is how I included div on Master page(outside ContentPlaceHolder):
<div id="DivTest" style="width: 200px;">
</div>
这是我在子页面上写的代码(在ContentPlaceHolder中):
This is the code I wrote on child page(inside ContentPlaceHolder):
<script language="javascript" type="text/javascript">
// function getwidth() {
var content_div = document.getElementById('DivTest');
var content_width = content_div.clientWidth;
alert('content_width=' + content_width + 'px');
// }
</script>
有效。
It worked.
这篇关于如何在内容页面访问母版页javascript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文