English 中文(简体)
从一个表格中通过php检索javascript输出
原标题:Retrieving javascript output from a form via php

我有一个隐蔽的领域,我试图打消用户的解决方案。 然后,处理工作结束时,通过实验室检索屏幕。 不幸的是,我对javascript的理解非常有限。 这里是我所拥有的。 我确实希望得到任何帮助。

<head>
    <script type="text/javascript">
        function xy(){
            document.write(screen.width + "x" + screen.height);
            document.getElementById( xy ).value;
            }           
    </script>
</head>




<form action="" method=post >

    //other fields here

    <input type="hidden" name="xy" id="xy" value=""/>
    <input type=submit name="button" value="button" /> 
</form>

当我看一看页源代码时,我是否应该看到“1366x768”等值? 现在,在加工方面,我要向营地提供类似信息。

if(isset($_POST[ xy ]) && (!empty($_POST[ xy ])){
 $blah = $_POST[ xy ];
 //sanatize $blah;
    }
最佳回答

你们可以使用

<script type="text/javascript">
    function setResolution()
    {
        document.getElementById( xy ).value = screen.width + "x" + screen.height;
    }
</script>

然后,在提交时,确保履行这一职能。

<input type="submit" name="button" value="button" onclick="setResolution()" />
问题回答

用途

function xy(){
    document.getElementById( xy ).value = screen.width + "x" + screen.height;

}

and 用途 the script tag or execute the function after rendering of the form else the element would not be found

EDITED: 增加

ulliw,

您不称职,这样你就拿不到任何东西。

如果你改变这种状况,即为你工作:

<head> 
<script type="text/javascript"> 
        document.write(screen.width + "x" + screen.height); //this will write on the html page 
        document.getElementById( xy ).value=screen.width + "x" + screen.height; // this will put the resolution in your form s hidden field
</script> 





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签