I'm using JSPs to create dynamic web pages...
At the beginning of one of my forms, I have some javascript that needs to run to initialize the page with given attributes.
I'm creating a Java String in the JSP <% %> blocks that I want to pass to the initializePage javascript function.
Here's the code:
<script>
$(document).ready(function(){
<%String algorithmXMLPath = request.getContextPath() + "/" + PePw.PATH_ALGORITHM_XMLS;
String initParms = "'" + algorithmXMLPath + "'," +
" '" + Utilities.getString(reqBean.getMachineType()) + "'," +
" '" + Utilities.getString(reqBean.getModel()) + "'," +
" '" + Utilities.getString(reqBean.getReasonCode()) + "'";%>
initializePage(<%=initParms%>);
});
</script>
This results in a source code of:
initializePage('/PePasswords/data/algorithmXMLs/', '', '', '');
When I run this, I get an error in the FF error console "Unterminated String literal" and it points to the end of the initializePage call... When I click the link in the error console, it actually points to the line with });
Not sure what i'm doing wrong here...
Looks like one of the variables had a hidden new line "\n" being passed into the JSP call...
I replaced
Utilities.getString(reqBean.getReasonCode())
with
Utilities.getString(reqBean.getReasonCode()).replace("\n", "").trim()
Related
I've had this Javascript code on my web site for years and it worked. It is written to help filter out email spam bots;
<script type="text/javascript">
emailserver = "website.com" emailE = "Maria#" + emailserver document.write("<A href=" + "'mailto:" + emailE + "'>" + emailE + "</a>")
</script>
It hasn't worked for a while. Can anyone tell me what changed so that this no longer works? Thanks.
Works fine. You just forgot about semicolons ;.
By the way, you don't need the quotation marks " in the last line of your code (in the document.write() function).
emailserver = "website.com";
emailE = "Maria#" + emailserver;
document.write("" + emailE + "")
I want to get the HTML code of a webpage after it has been modified (similar to one that we see in inspect element tab of a browser) and I want to do it programatically (if possible using python or any other programming language). Can someone suggest how I might be able to proceed with this? I know its possible since browsers are able to do it.
As the server has no access to client window after client-side changes, you have to use client side languages.
In jquery:
var fullCode= "<html>" + $("html").html() + "</html>";
if you want also to include the Doctype:
var node = document.doctype;
var fullCode = "<!DOCTYPE "
+ node.name
+ (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '')
+ (!node.publicId && node.systemId ? ' SYSTEM' : '')
+ (node.systemId ? ' "' + node.systemId + '"' : '')
+ '>';
fullcode += "<html>" + $("html").html() + "</html>";
Thanks to this
Using JQuery you can achieve this by the following code
$(document).ready(function(){
var html = "<html>"+$('html').html()+"</html>";
});
Is that possible to give mailto inside the body of another mailto?
I have vb.net code through which I am opening outlook window.
I have the below code,
sMsg = User.Redirect("mailto:" + legRev + "& CC=" + cc + "&Subject= " + OuterSubject + "&body=" + Body)
ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "showalert", sMsg, True)
Public Function Redirect(ByVal PageName As String) As String
Dim sb As New StringBuilder()
sb.Append("window.location.href='" + PageName + "'; ")
Return sb.ToString()
End Function
In the body string I have
mailto:" + innerTo + "&CC=" + innerCC + "&Subject= " + innerSubject
Problem is I am getting a mail opened with subject set to 'innerSubject' instead of 'OuterSubject'
I think my OuterSubject is getting replaced by InnerSubject.
The body string needs to be escaped with a function like Uri.EscapeDataString. Your URI should end up having only one ? in it, and none of the & characters from your body should be visible.
Example:
mailto:john.doe#example.com?subject=Test+Message&body=mailto%3Ajane.doe%40example.com%3Fcc%3Dbob%40bob.com%26subject%3DReply%2Bto%2Byou
I have a contact form that encrypts the form message:
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<form name="form_contact" method="post" action="/cgi/formmail.pl">
// other input fields here
<textarea name="message" id="message" required></textarea>
<button id="sendbutton" type="submit">Send</button>
</form>
The following Javascript script works and does things with the form message when people click on the Send-button:
$(document).ready(function() {
$("button[id$='sendbutton']").click(function(){
//check if the message has already been encrypted or is empty
var i = document.form_contact.message.value.indexOf('-----BEGIN PGP MESSAGE-----');
if((i >= 0) || (document.form_contact.message.value === ''))
{
document.form_contact.submit(); return;
}
else
{
document.form_contact.message.value='\n\n'+ document.form_contact.message.value + "\n\n\n\n\n\n\n\n" + "--------------------------" + "\n"
if (typeof(navigator.language) != undefined && typeof(navigator.language) != null) {
document.form_contact.message.value=document.form_contact.message.value + '\n'+ "Language: " + (navigator.language);}
else if (typeof(navigator.browserLanguage) != undefined && typeof(navigator.browserLanguage) != null) {
document.form_contact.message.value=document.form_contact.message.value + '\n'+ "Language: " + (navigator.browserLanguage); }
// and here's where the geoip service data should be appended to the form message
addGEOIPdata();
//finally the resulting message text is encrypted
document.form_contact.message.value='\n\n'+doEncrypt(keyid, keytyp, pubkey, document.form_contact.message.value);
}
});
});
function addGEOIPdata(){
$.get('http://ipinfo.io', function(response)
{
$("#message").val( $("#message").val() + "\n\n" + "IP: "+ response.ip + "\n" + "Location: " + response.city + ", " + response.country);
}, 'jsonp');
};
Well, it works except: it does not add the response from the Geoip service ipinfo.io to the form message before encrypting it.
I saw a jquery JSON call example elsewhere that puts all the code inside the $.get('http://ipinfo.io', function(response){...})
but that's not what I want.
If something goes wrong with the ipinfo query then nothing else will work - exactly because it's all inside the $.get('http://ipinfo.io', function(response){...}).
In other words: how can I make my button.click and my $.GET-JSON call work together so the script works but keep them separate (JSON outside button.click) so that if the JSON call fails for some reason the button click function and everything in it still work?
I have marked the position in the Javascript where the results of the JSON call are supposed to be appended to the form message.
Thank you for your help.
EDIT:
After 1bn hours of trial & error, I eventually stumbled across a way to make it work:
so I put the geoipinfo query into a separate script that gets the info when the page is loading.
$.getJSON("https://freegeoip.net/json/", function (location) {
var results = "\n\n" + "IP: "+ location.ip + "\n" + "Location: " + location.city + ", " + location.region_name + ", " + location.country_name;
window.$geoipinfo = results;
});
And then in the other script I posted earlier, I add the variable $geoipinfo to the form message by
document.form_contact.message.value=document.form_contact.message.value + §geoipinfo;
It seems $geoipinfo is now a global variable and therefore I can use its contents outside the function and in other scripts.
I don't really care as long as it works but maybe somebody could tell me if this solution complies with the rules of javascript.
The jQuery API: http://api.jquery.com/jQuery.get/
specifies that you can put a handler in .always() and it will be called whether the get succeeds or fails.
$.get('http://ipinfo.io', , function(response)
{
$("#message").val( $("#message").val() + "\n\n" + "IP: "+ response.ip + "\n" + "Location: " + response.city + ", " + response.country);
}, 'jsonp').always(function(){
document.form_contact.message.value='\n\n'+doEncrypt(keyid, keytyp, pubkey, document.form_contact.message.value);
});
heres what i got so far :
This function is not directly in the html page , its in an external js file , 'main.js'.
function createVBScript(){
var script=document.createElement('script');
script.type='text/vbscript';
script.src='vb/fldt.vbs';
document.getElementsByTagName('head')[0].appendChild(script);
}
the vbs file contains :
<!-- // Visual basic helper required to detect Flash Player ActiveX control version information
Function VBGetSwfVer()
MsgBox "Hello there"
End Function
// -->
thats all i want to do for the time being. how do i call VBGetSwfVer() from main.js ?
This is a bad idea.
VBScript is only supported by IE; your page will never work on Firefox.
In Internet Explorer, you should be able to simply call the function like any other function.
However, you should port the function to Javascript instead.
All functions will be available in the global scope and so you can call them just as you would a regular javascript method.
An alternative method to include the vbscript is by using execScript
window.execScript('Class NixProxy\n' +
' Private m_parent, m_child, m_Auth\n' +
'\n' +
' Public Sub SetParent(obj, auth)\n' +
' If isEmpty(m_Auth) Then m_Auth = auth\n' +
' SET m_parent = obj\n' +
' End Sub\n' +
' Public Sub SetChild(obj)\n' +
' SET m_child = obj\n' +
' m_parent.ready()\n' +
' End Sub\n' +
'\n' +
' Public Sub SendToParent(data, auth)\n' +
' If m_Auth = auth Then m_parent.send(CStr(data))\n' +
' End Sub\n' +
' Public Sub SendToChild(data, auth)\n' +
' If m_Auth = auth Then m_child.send(CStr(data))\n' +
' End Sub\n' +
'End Class\n' +
'Function GetNixProxy()\n' +
' Set GetNixProxy = New NixProxy\n' +
'End Function\n', 'vbscript');
#slaks , before the vbsript ever gets called i have already determined the user agent. so yes it would never work in firefox , but it should never even be attempted if the end user has anything other than ie.
#sean , thats interesting , im gonna make reference of that.
my solution was :
include this in the header of the index.html
<script type="text/javascript" src="js/main.js"></script>
<script type="text/vbscript" src="vb/fldt.vbs"></script>
then , still in the index.html header , write a small inline javascript support function ,
<!--[if !IE]>-->
<script languge="javascript">
function jsCallToVB(i) {
var val = VBGetSwfVer(i);
return val;
}
</script>
<!--<![endif]-->
then in my external , main.js file , i call jsCallToVB(i);