My webapp (written in ASP.NET) is laid out with MasterPages. In the content area of the Masterpage, the is an iframe that I display the pages. On navigation click I simple set the ContentUrl (within the contentplaceholder) to a new url and it refreshes the content area.
Here is the method that does that:
Protected Sub radprojecttree_NodeClick(sender As Object, e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles radprojecttree.NodeClick
Dim ts As String = e.Node.Attributes("contentpage")
radpancontentholder.ContentUrl = ts
If (Not SiteUser Is Nothing) Then
BSRMaster.navtree.NavTree_InitNodes(Nothing, e.Node)
End If
End Sub
But was I also need is to set the ContentUrl within javascript at certain times and show the page. However when I set the ContentUrl the page does not show. how do I refresh the contentplaceholder in javascript?
Here is the code that I have for javascript so far:
function goToPage(){
var strLoc = "";
switch (AutoExpandOption) {
case "RestoreLastNode" :
strLoc = readCookie(strUser + 'LastPageLocation');
if ((typeof(strLoc) == "undefined") || (strLoc == null)) {
strLoc = 'Secure/TaskManager.aspx';
createCookie(strUser + 'LastPageLocation', 'TaskManager.aspx', 100);
}
break;
case "GoToTaskManager" :
strLoc = 'Secure/TaskManager.aspx';
break;
case "GoToDashboard" :
strLoc = 'Secure/Dashboards.aspx';
break;
}
if (strLoc != "") {
var ph = $find('ctl00_radpancontentholder');
ph._contentUrl = strLoc;
//document.getElementById('pagecontentframe').src = strLoc;
}
}
$find was being called before the page loaded fully, therefore no controls were present
Related
I am using functionality where if validation error comes then goto link is generating an id of required component with focus() on the top of the page. On click of that link the required component is highlighted. Now its working if error is in same tab. But first tab is active focus function not pointing the required text box inside third tab.
void encodeGotoLabel(FacesContext context, UIComponent component, ResponseWriter writer,
FacesMessage msg) throws IOException {
String id = getid(context, msg);
if (id != null && !FacesMessage.SEVERITY_INFO.equals(msg.getSeverity())
&& !FacesMessage.SEVERITY_FATAL.equals(msg.getSeverity())) {
String inputLabel = findInputLabel(context, id);
if (inputLabel != null) {
ResourceBundle bundle ="bundle";
writer.writeText(" (", null);
writer.writeText(bundle.getString("goTo") + " ", null);
writer.startElement("a", component);
writer.writeAttribute("href", "javascript:document.getElementById('" + id
+ "').focus();",
null);
writer.writeText(inputLabel, null);
writer.endElement("a");
writer.writeText(")", null);
}
}
}
This function loops on a group of tabs and check if there is an error, if so it switch to it and focus on the required field, all you need to do is add it in your function :
var tabs = PF('tabViewWv').getLength(); //tabViewWv is WidgetVar name
for (var iter = 1; iter <= tabs ; iter++) {
if ($('#form\\:tabView\\:tab' + iter).find(':input').hasClass('ui-state-error')) {
PF('tabViewWv').select(iter - 1);
return false;
}
}
I've been sweating over this the last three days, I am baffled!
The input html launches an xml scan of a web site to gather text, images and links which populate a form for the user to select what they want to save. (The output eventually becomes a bookmark stored at greenfloyd.org.) The problem began a month or so ago, the scan started crashing with a "Forbidden 403" error pointing to my php code file, on the gf server (dir/file permission at 0644). The problem revolves around the links (url and text) gathered and placed into a box , the url is put in the value, and the link text into the innerHTML. The default is that none of the links are selected, the user can then select one or more links from this box, or manually add a link via two fields that get put into the select box, and become part of the form.
<form id = "bmInputForm" onsubmit = "bmSub(); return false;" onreset = "bmInputFormReset();" action = "http://greenfloyd.org/greenfloyd/php/bm_input_xml.php" method = "post" enctype = "multipart/form-data" class = "readerBox">...
<code><input type = "url" id = "link1Url" class = "input_size" size = "40" maxlength = "250" value ="" onclick = "this.select();" title = "Enter a standard url for this related link.">
<input id = "link1Title" class = "input_size" size = "40" maxlength = "150" value = "" onclick = "this.select();" title = "Enter a short title for this related link.">
<button type = "button" onclick = "relatedAdd()" title = "Add to related links list.">[+]</button>
<hr style="width:25%;">
<select id = "relatedSelect" name = "related_select[]" multiple title = "To select/unselect hold down the Ctrl key and click an option." onchange = "relatedCheck();" style = "width:80%;"></select></code>
The scan is an ajax xml call and returns elements from the target url, including the following:
<code>//echo "<related url='".rawurlencode($valid_url)."' txt='".htmlspecialchars($related_text, ENT_QUOTES,'UTF-8')."'></related>";
err = false;
try { var relatedNode = ( xmlDoc.getElementsByTagName("related") ) ? xmlDoc.getElementsByTagName("related") : false; }
catch(err) { err = true; relatedNode = false; }
result += ( !relatedNode ) ? "<li>Scanner unable to retrieve relatedNode || "+err+"</li>" : "<li>Link scan found: "+relatedNode.length+" entries.</li>";
if( relatedNode.length > 0 )
{
clearCache("relatedSelect");
var selObj = document.getElementById("relatedSelect");
for(var i = 0; i < relatedNode.length; i++)
{
val = unescape(relatedNode[i].getAttribute("url"));
str = unescape(relatedNode[i].getAttribute("txt"));
opt = document.createElement("option");
opt.value = val;
opt.innerHTML= ( str.length > 50 ) ? str.substring(0,48)+"..." : str;
selObj.appendChild(opt);
}
}
</code>
All the above is working fine. But everything goes south at submit time when the urls, (the value), are external relative to greenfloyd.org. Then, I get the "Go away and don't come back message..." On the other hand, if the urls point to greenfloyd there's no problem and the bookmark is published, with links. It's almost like I were trying to call the local script from some other domain. The uls are not in any linkable context, they are treated as plain text in the value attribute of the option. Although I do combine the url with the text using a seperator (,) between them so that php can unpack the value to produce seperate url and text fields that are stored on msqli... it's hacky, but it works, or at least it use to and I've yet to find a better alternative. One other odd thing: when I gather the links in greenfloyd.org there are a couple external links and they are accepted!?
<code>
function bmSub()
{
...
var selObj = document.getElementById("relatedSelect");
var url, txt, val, sendCt=0;
for ( var i = 0; i < selObj.options.length; i++ )
{
if ( selObj.options[i].selected )
{
url = selObj.options[i].value.trim();
txt = selObj.options[i].innerHTML;
val = url+"*,*"+txt; // pack url and txt into the value attribute, php unpacks it into 2 db fields
selObj.options[i].value = val;
sendCt +=1;
}
}
resultDisplay("Link count: "+sendCt);
var formElement = document.getElementById("bmInputForm");
var formData = new FormData(formElement);
var urlX = encodeURI("http://greenfloyd.org/greenfloyd/php/bm_input_xml.php?sid="+Math.random());
xmlObj = GetXmlHttpObject();
xmlObj.open("POST", urlX, false);
xmlObj.send(formData);
// pause echo "<return err='$err' msg='$msg'></return>";
try
{
xmlDoc = xmlObj.responseXML;
var returnNode = xmlDoc.getElementsByTagName("return");
err = ( returnNode[0].getAttribute("err") == "1" ) ? true : false;
msg = unescape(returnNode[0].getAttribute("msg"));
}
catch(e)
{
msg = "bmSub status : "+e+"<br>xml: "+xmlObj.statusText+", "+xmlObj.status+", size: "+xmlObj.responseText.length;
err = true;
}
resultDisplay(msg);
if ( err ) return;
</code>
I am trying to insert google ads after the first paragraph of the text box on my mediawiki site. My code is based on https://www.mediawiki.org/wiki/Extension:AdsWherever.
I have a function that returns a tag which will render the google ads code.
I am using javascript to check if the tag is there, if it isn't I'm inserting it after the first paragraph.
The issue is none of the rest of the text in the text box is showing after the google ads. I think this may because the function is returning a value and breaking out of the code and so not allowing the rest of the javascript code to run. (I may be wrong but this is what I think the issue is).
How do I insert the google ads in the correct place and still show the text after the ads?
I don't mind skipping the function altogether and just using javascript to insert the code but I don't know how to write the javascript so var b contains the javascript for the google ads.
This is my code:
$wgHooks['ParserFirstCallInit'][] = 'AdsSetup';
$wgHooks['EditPage::showEditForm:initial'][] = 'CheckHasTag';
function AdsSetup( &$parser ) {$parser->setHook( 'ads', 'AdsRender' ); return true;}
function AdsRender($input, $args ) {
$input =""; $url = array(); global $wgOut;
$ad['goo1'] = '<html><br><script type="text/javascript">
google_ad_client = "xxx";
google_ad_width = 728;
google_ad_height = 90;
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br></html>';
$media = $args['media'];
return $ad[$media];
}
// check if content has <goo1> tag
function CheckHasTag($editPage){
global $wgOut;
$wgOut->addScript('<script type="text/javascript">
var editTextboxText = document.getElementById("wpTextbox1").value;
var searchFor = "goo1";
var searchResult = editTextboxText.search(searchFor);
if(searchResult == -1){
var a = editTextboxText;
var b = "\n<ads media=goo1>\n";
var findP = "\n";
var p = editTextboxText.search(findP);
var position = p;
document.getElementById("wpTextbox1").value = a.substr(0, position) + b + a.substr(position);
}
</script>');
return true;
}
var editTextboxText = document.getElementById("mw-content-text").innerHTML;
var searchFor = new RegExp("goo1");
if (searchFor.test(editTextboxText) === false) {
var ad = document.createElement('ads');
ad.setAttribute('media', 'goo1');
var parent = document.getElementById("mw-content-text").getElementsByTagName('p')[0].parentNode;
var secondParagraph = document.getElementById("mw-content-text").getElementsByTagName('p')[0].nextSibling;
parent.insertBefore(ad, secondParagraph);
}
JSfiddle
I'm not too good on the whole JavaScript (I can do some basic validations) but this isn't my zone
I've got a piece of code below that I'm trying to understand what it does, I can read any code and understand a few parts, but this just stumped me.
Here:
function tm_search_click() {
if (document.getElementById('tm').value == 'Enter your trademark') {
document.getElementById('tm').style.backgroundColor = '#fcc';
return false;
} else {
window.location = '?tm=' + escape(document.getElementById('tm').value);
return true;
}
}
function qs(a) {
a = a.replace(/[[]/, "\[").replace(/[]]/, "\]");
var b = "[\?&]" + a + "=([^&#]*)";
var c = new RegExp(b);
var d = c.exec(window.location.href);
return d == null ? "" : decodeURIComponent(d[1]).replace(/+/g, " ")
}
if (qs("tm") != "") {
tm_trademark = document.getElementById("tm").value = unescape(qs("tm"));
tm_partner = "migu2008";
tm_frame_width = 630;
tm_frame_height = "auto";
tm_trademark_country_code = "GB";
tm_css_url = "http://remarqueble.com/api/theme/search_corporate.css";
document.getElementById("tmLoading").style.display = "block";
tm_on_search_result = function () {
document.getElementById("tmLoading").style.display = "none";
document.getElementById("tmLoaded").style.display = "block"
}
} else {
tm_search_method = "none"
}
That is all of it without the <script> tags.
Could I also edit this code so that it searches are made based on what option the user inputs?
I think it works like this (assuming that this is in tags inside html page)
Page loads.
The script checks if URL has 'tm' parameter. If it has, then it sets bunch of tm_.. parameters and callback function. I don't know how they are used.
User clicks something that triggers the tm_search_click
Script sets new URL for the page and browser starts loading that
Goto step 1.
i successfully added a contextmenu to my webbrowser with this javascript code:
public void AttachContextMenu()
{
try
{
if ((App.Current as App).Browser.IsScriptEnabled)
{
(App.Current as App).Browser.InvokeScript("execScript", "function FindParentLink(item) \r\n{\r\n\tif (!item.parentNode)\r\n\t\treturn null;\r\n\tif (item.tagName.toLowerCase() == 'a') \r\n\t{\r\n\t\treturn item;\r\n\t} \r\n\telse \r\n\t{\r\n\t\treturn FindParentLink(item.parentNode);\r\n\t}\r\n}\r\n\r\nfunction FindParentImage(item) \r\n{\r\n\tif (!item.parentNode)\r\n\t\treturn null;\r\n\tif (item.tagName.toLowerCase() == 'img') \r\n\t{\r\n\t\treturn item;\r\n\t} \r\n\telse \r\n\t{\r\n\t\treturn FindParentImage(item.parentNode);\r\n\t}\r\n}\r\n\r\nfunction HandleContextMenu() \r\n{\r\n\tvar linkItem = FindParentLink(event.srcElement);\r\n var imageItem = FindParentImage(event.srcElement);\r\n var notifyOutput = '';\r\n if (linkItem != null) if (linkItem.href != null) notifyOutput += linkItem.href;\r\n if (imageItem != null) if (imageItem.src != null) notifyOutput += imageItem.src;\r\n if (notifyOutput != '')\r\n window.external.notify(notifyOutput);\r\n else\r\n\t\twindow.external.notify('NOTLINKIMG');\r\n}");
(App.Current as App).Browser.InvokeScript("execScript", "document.oncontextmenu = HandleContextMenu;");
}
}
catch
{
}
}
this method is used everytime the browser navigated.
So, the scriptnotify code, which will be used when the user holds a link :
if (e.Value.ToString() != null && IsValidUri(e.Value.ToString()))
{
ContextMenu cm = new ContextMenu();
MenuItem menuItem0 = new MenuItem() { Header = "X", Tag = e.Value };
menuItem0.Click += new RoutedEventHandler(X_Click);
MenuItem menuItem1 = new MenuItem() { Header = "Y", Tag = e.Value };
menuItem1.Click += new RoutedEventHandler(Y_Click);
MenuItem menuItem2 = new MenuItem() { Header = "Z", Tag = e.Value };
menuItem2.Click += new RoutedEventHandler(Z_Click);
cm.Items.Add(menuItem0);
cm.Items.Add(menuItem1);
cm.Items.Add(menuItem2);
ContextMenuService.SetContextMenu(Browser, cm);
cm.IsZoomEnabled = false;
cm.VerticalOffset = mouseClickPosition.Y;
cm.IsOpen = true;
}
so far, i hope i made everything right.
now, it randomly works. nearly 50% of tries cause a error, Visual studio navigates to a blue-white frame named "No source available" and throws a NullReferenceException.
Where should this be solved? already set a try-catch block around the hole 2 method, no change :/
hope you have some ideas
greets
roqstr
don't got it working, but there's a workaround:
AttachContextMenu()
-> holding a link will push the url to the scriptnotify method.
build a custom contextmenu & everything is fine.